#include <iostream>
#include <string>
#include <vector>
#include <memory>

#include "utils.h"
#include "conv.h"
#include "timer.h"
using namespace std;

int main(){
    check_float_bits();

    int ks = 3;
    int ic = 128;
    int oc = 128;
    int stride = 1;
    int padding = 1;

    string fil_prefix = "/mnt/HD_2/luojiapeng/sparse_ncnn/tmp/res18_layer2.1.conv2";

    string input_file = fil_prefix + "_input.dat";
    vector<int> input_shape = {128, 28, 28};
    vector<float> input_blob;
    read_blob(input_file, shape2size(input_shape), input_blob);

    string output_file = fil_prefix + "_output.dat";
    vector<int> output_shape = {128, 28, 28};
    vector<float> output_blob;
    read_blob(output_file, shape2size(output_shape), output_blob);

    string weight_file = fil_prefix + "_weight.dat";
    vector<int> weight_shape = {128, 128, 3, 3};
    vector<float> weight_blob;
    read_blob(weight_file, shape2size(weight_shape), weight_blob);
    
    Conv conv(weight_blob, ic, oc, ks, stride, padding);
    vector<float> output;
    Timer timer("total");

    cout << "-------------------- forward_direct1 -----------------------------" << endl;
    timer.reset();
    for(int i = 0; i<10; i++){
        timer.start();
        conv.forward_direct1(input_blob, input_shape, output);
        timer.pause();
    }
    cout << timer.output() << endl;
    cout << conv.timer_conv.output() << endl;
    cout << conv.timer_pad.output() << endl;

    if(!vec_equal(output, output_blob)){
        cout << "compare fails" << endl;
    }
    cout << "compare success" << endl;

    
    cout << "-------------------- forward_im2col_gemm -----------------------------" << endl;
    timer.reset();
    for(int i = 0; i<10; i++){
        timer.start();
        conv.forward_im2col_gemm(input_blob, input_shape, output);
        timer.pause();
    }
    cout << timer.output() << endl;
    cout << conv.timer_im2col.output() << endl;
    cout << conv.timer_gemm.output() << endl;

    if(!vec_equal(output, output_blob)){
        cout << "compare fails" << endl;
    }
    cout << "compare success" << endl;
}